package com.frame.service.base.biz.convert.bak.dict;

import com.frame.common.component.dict.IDict;
import com.frame.convert.core.AbstractConverter;
import com.frame.convert.core.ConvertContext;
import com.frame.convert.core.ConvertListContext;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/*
 * @author zhangyan
 * @date 2021-04-10 11:07:08
 **/
public class DictsNameConverter extends AbstractConverter<DictsName, List<IDict>,String> {
    @Override
    public String convert(ConvertContext<DictsName, List<IDict>> context) {
        List<IDict> sourceValueList = context.getSourceValue();
        if (sourceValueList==null||sourceValueList.isEmpty()) return null;
        return sourceValueList.stream().map(IDict::getName).collect(Collectors.joining(","));
    }

    @Override
    public Function<ConvertContext<DictsName, List<IDict>>, String> convertList(ConvertListContext<DictsName, List<IDict>> convertListContext) {
        return this::convert;
    }
}
